package com.studyroom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.studyroom.dto.QuestionDTO;
import com.studyroom.entity.Answer;
import com.studyroom.entity.Question;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface QuestionMapper extends BaseMapper<Question> {
    @Select ("select q.id,q.title,q.solve_id,q.content,q.created,u.username,u.icon from question as q inner join user as u on q.user_id=u.id where q.type=#{type}")
    List<QuestionDTO> getByType(String type);
    @Select ("select q.id,q.title,q.solve_id,q.content,q.created,u.username,u.icon from question as q inner join user as u on q.user_id=u.id")
    List<QuestionDTO> getAll();
    @Select ("select q.id,q.title,q.solve_id,q.content,q.created,u.username,u.icon from question as q inner join user as u on q.user_id=u.id where q.title like '%${title}%'")
    List<QuestionDTO> getListByTitleWithFuzzy(String title);
    @Select ("select count(*) from q_like l where l.question_id=#{id}")
    Long getLikeNumberById(Long id);
    @Select (("select count(*) from answer a where a.question_id=#{id}"))
    Long getAnswerNumberById(Long id);
    @Select ("select l.user_id from q_like l where l.question_id=#{id}")
    List<Long> getLikesById(Long id);

}
